function [backupPathTable] = calculateBackupPath(primaryPath, primaryPathTable, disp_loc, matrix)
  pr = length(primaryPathTable);
  
  backupPathTable = zeros(1,1);
%   pathBetweenTwoNodes = zeros(1,1);
  
  numberOfBackupPathNodes = 1;
  middleNode = 0;
  dist1 = -1;
  
  sender = primaryPathTable(1,1);
  backupPathTable(numberOfBackupPathNodes) = sender;
  
  for i = 2:pr
      counter = 1;
      changeNode = 1;
      receiver = primaryPathTable(i);
      middleNodeArray = zeros(1,1);
      DBNR = zeros(1,1);
      
       
      [neighborsS] = node_neighbors(sender,matrix);%This function will return the neighbors for certain node.
      [neighborsR] = node_neighbors(receiver,matrix);
      
      S = length(neighborsS);
      R = length(neighborsR);
      
      for j = 1 :S
               sndNeigh = neighborsS(j);
               [xR,yR]=find_Coordinates(receiver, disp_loc);

               for q = 1:R           
                  rcvNeigh = neighborsR(q);
                  if sndNeigh == rcvNeigh
                      LB = length(backupPathTable);
                      %#######################This loop for make each node protect only one link#############                
                      for d = 1:LB
                         if sndNeigh == backupPathTable(d)
                             changeNode = -1;
                         end
                      end
                      if changeNode == 1
                          [xN,yN]=find_Coordinates(sndNeigh, disp_loc);
                          dist2 = distance(xN,yN,xR,yR);                      
                          if dist1 < dist2
                              middleNodeArray(counter) = sndNeigh;
                              DBNR(counter) = dist2;
                              counter = counter + 1;
                              middleNode = sndNeigh;
                              dist1 = dist2;
                          end  
                      end                      
                  end
                  changeNode = 1;
               end            
       end       
       if middleNode ~= 0
           sender = receiver;
           numberOfBackupPathNodes = numberOfBackupPathNodes +1;
           backupPathTable(numberOfBackupPathNodes) = middleNode;
           numberOfBackupPathNodes = numberOfBackupPathNodes +1;
           backupPathTable(numberOfBackupPathNodes) = sender;
       end
  end
    % Check all the nodes at the backup path that should no one use more than once.
    %[backupPathTable] = nodeUseOnce(primaryPathTable, backupPathTable, disp_loc,matrix);
    [backupPathTable] = nodeUseOnce(primaryPath, backupPathTable, disp_loc,matrix);
    
    
    % Draw the backup path
    if dist1 ~= -1 
        r = 1;
        g = 0;
        b = 0;
        drawPath(backupPathTable, disp_loc, r, g, b);                               
    else
        disp('There is no backup path available.');        
    end
end
